package com.dao;

import java.io.Serializable;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;

import com.dao.factory.ConnectionFactory;
import com.dao.generic.GenericDAO;
import com.model.Departamento;
import com.model.Disciplina;

public class DepartamentoDAO extends GenericDAO implements Serializable {

	/**
	 * 
	 */
	private static final long serialVersionUID = -8598691524231207908L;

	public List<Departamento> retornaDepartamentos() throws SQLException {
		List<Departamento> departamentos = new ArrayList<Departamento>();

		Connection conn = null;
		PreparedStatement pstm = null;
		ResultSet rs;

		StringBuilder sb = new StringBuilder();

		sb.append(" SELECT  ")
		.append(" codigo_departamento as codigo ")
		.append(", nome as nome ")
		.append(" FROM departamento ");
	

		try {

			conn = ConnectionFactory.getConnection();
			pstm = conn.prepareStatement(sb.toString());

			rs = pstm.executeQuery();

			while (rs.next()) {
				Departamento departamento = new Departamento();
				departamento.setCodigo(rs.getString("codigo"));
				departamento.setNome(rs.getString("nome"));
				
				
				departamentos.add(departamento);
			}

		} catch (Exception e) {

			e.getMessage();
		} finally {

			pstm.close();
			conn.close();
		}

		return departamentos;
		
	}

}
